#include "acc_user.h"
#include "veriuser.h"

#include "stdlib.h"


// Data structure
struct intrData {
  int intr;
  handle reg;
} workarea;

// Main routine which sync intr pin status from server
void intrGen () {
  // Get the stored workarea
  struct intrData *data = ( struct intrData * )tf_igetworkarea(tf_getinstance());

  io_printf("%d Current intr = %d\n",tf_gettime(), data->intr);

  // Drive the clock signal in HDL
  tf_putp (1, data->intr);
}

// checktf() routine
// This function inits the objects and also stores the object in workarea
void intrGenInit() {
  struct intrData *data = &workarea;
  workarea.intr  = 0;
  workarea.reg   = acc_handle_tfarg(1);

  tf_setworkarea(data);
}

// misctf() routine
// This routine is called after 1 tick
void intrReactive (int data, int reason, int paramvc) {
  // if callback reason is reactive, then call intrGen function
  if (reason == reason_reactivate) {
    intrGen();
  }
  // Set the callback delay to 1 tick
 // tf_setdelay(1);
}

void assert_intr(bool on)
{
	 s_setval_delay delay_s;
	 s_setval_value value_s;

     value_s.format    = accIntVal;
     delay_s.model     = accNoDelay; 
     delay_s.time.type = accTime;
     delay_s.time.low  = 0;
     delay_s.time.high = 0;

	workarea.intr=on;
	value_s.value.integer =  workarea.intr;
	acc_set_value(workarea.reg,&value_s,&delay_s);
}